package com.yuejian_06.yuejian_06.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.activity.PicInfoActivity;
import com.yuejian_06.yuejian_06.bean.PicBean;

import java.util.List;

/**
 * Created by __ZL__ on 2017/10/12.
 */

public class PicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public PicAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.piclistcardview,parent,false);
        return new PicAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PicBean entity =(PicBean) mDataList.get(position);
        //System.out.println("----"+position+"----"+entity.getPic1());
        if (null == entity)
            return;
        PicAdapter.ViewHolder viewHolder = (PicAdapter.ViewHolder) holder;
        viewHolder.user_name.setText(entity.getUser_name());
        //String p = String.valueOf(entity.getPrice());
        viewHolder.club_name.setText("#"+entity.getClub_name()+"#");
        viewHolder.pic_main.setText(entity.getPic_main());
        if (!"".equals(entity.getUser_pic()))
            Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/userpics/"+entity.getUser_pic()).into(viewHolder.user_pic);
        //System.out.println("http://10.0.2.2/yuejian/Public/userpics/"+entity.getUser_pic());
        if (!"".equals(entity.getPic1()))
            Picasso.with(mContext).load("http://10.0.2.2/yuejian/Public/picpics/"+entity.getPic1()).into(viewHolder.pic1);
        //System.out.println("http://10.0.2.2/yuejian/Public/picpics/"+entity.getPic1());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,PicInfoActivity.class);
                intent.putExtra("pic_id",entity.getPic_id()+"");
//                intent.putExtra("user_name",entity.getFood_id()+"");
//                intent.putExtra("club_name",entity.getFoodname()+"");
//                intent.putExtra("pic_main",entity.getPrice()+"");
//                intent.putExtra("user_pic",entity.getIntro()+"");
//                intent.putExtra("pic1",entity.getPic()+"");
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView user_name,club_name,pic_main;
        private ImageView user_pic,pic1;
        public ViewHolder(View itemView) {
            super(itemView);
            user_name = (TextView) itemView.findViewById(R.id.user_name);
            club_name = (TextView) itemView.findViewById(R.id.club_name);
            pic_main = (TextView) itemView.findViewById(R.id.pic_main);
            user_pic = (ImageView) itemView.findViewById(R.id.user_pic);
            pic1 = (ImageView) itemView.findViewById(R.id.pic1);
        }
    }
}
